/*******************************************************************************
"SCARCITY WITHOUT LEVIATHAN: The Violent Effects of Cocaine Supply Shortages
in the Mexican Drug War"
J.C. Castillo, D. Mejia, P. Restrepo
*********************************************************************************

This do file produces:

TABLE 6: "Differential effects of cocaine seizures in Colombia on the homicide 
rate in Mexican municipalities located at different distances from US entry points,
with different cartel presence and PAN support."

The table presents estimates of the interaction between cocaine seizures in 
Colombia (measured at the monthly level in log), proximity to US entry points
(measured in 100 km), cartel presence, and PAN support on violence in Mexico 
municipalities.

Before running: set the path to current folder at line 26
*******************************************************************************/

clear all
set matsize 5000
set more off

*Set local folder
local folder /*SET THE PATH TO CURRENT FOLDER HERE*/

*Set working directory
cd `folder'
use dta/CastilloMejiaRestrepo.dta

keep if timeTS >= ym(2006,12)
tab year if  timeTS >= ym(2006,12), gen(yy)
local tscontrols t t2 t3 yy2 yy3 yy4 yy5

/*Seizure in Colombia*/
gen supplyShock=log(cocaincCol)

/*Interactions: Seizures x Cartels x Distance:*/
*Seizures in Colombia x Proximity to the US:
gen interMain=-supplyShock*distEntradasPrinc*10
*Seizures in Colombia x Cartel presence:
gen inter_hayCarteles=supplyShock*hayCarteles
*Seizures in Colombia x Proximity to the US x Cartel presence:
gen inter_dist_hayCarteles=-supplyShock*distEntradasPrinc*(hayCarteles-1)*10
*Seizures in Colombia x Rival Cartels:
gen inter_vCarteles=supplyShock*vCarteles
*Seizures in Colombia x # Cartels:
gen inter_nCarteles=supplyShock*nCarteles
*Seizures in Colombia x Proximity to the US x Rival Cartels:
gen inter_dist_vCarteles=-supplyShock*distEntradasPrinc*(vCarteles-1)*10
*Seizures in Colombia x Various Cartels:
gen inter_eneCarteles=supplyShock*eneCarteles
*Seizures in Colombia x Proximity to the US x Various Cartels:
gen inter_dist_eneCarteles=-supplyShock*distEntradasPrinc*(eneCarteles-1)*10

sum distEntradasPrinc
gen distanceDem=distEntradasPrinc-r(mean)
gen inter2=-supplyShock*distanceDem^2*100

/*Demean PAN Support*/
sum dPANsupport
gen dPANsupportDem=dPANsupport-r(mean)

/*Interactions: Seizures x PAN support x Distance:*/
gen inter_supply_dpan=supplyShock*dPANsupportDem
gen inter_supply_dpan_dist=-supplyShock*distEntradasPrinc*(dPANsupport-1)*10

/*Create dependent variable: homicide rate*/
gen tasa_hom = homSIMBAD/poblacion * 100000 * 12
quietly sum tasa_hom if tasa_hom > 0 & codmpio != 9000, d
local shift=r(p90)
gen term=(tasa_hom+`shift')/tasa_hom
sum term
local adj=r(mean)
gen log_tasa_hom =`adj'*log(tasa_hom+`shift')


/*Differential trends*/
foreach var in `tscontrols'{

*trend by distance from US entry points
gen interdif_`var'=`var'*distEntradasPrinc

*trends by number of cartels
gen intercart_hayCarteles`var'=`var'*hayCarteles
gen intercart_vCarteles`var'=`var'*vCarteles
gen intercart_eneCarteles`var'=`var'*eneCarteles
gen intercart_nCarteles`var'=`var'*nCarteles

gen intercart_hayCarteles_dist_`var'=distEntradasPrinc*hayCarteles*`var'
gen intercart_vCarteles_dist_`var'=distEntradasPrinc*vCarteles*`var'
gen intercart_eneCarteles_dist_`var'=distEntradasPrinc*eneCarteles*`var'
gen intercart_nCarteles_dist_`var'=distEntradasPrinc*nCarteles*`var'

*trends by PAN support
gen interpan_pan_`var'=`var'*dPANsupportDem
gen interpan_pandist_`var'=`var'*dPANsupportDem*distEntradasPrinc

}

/****************************************/
/**********    Panel A     **************/
/********** All Mexico     **************/
/****************************************/

/*****   Poisson model: cols 1-3     ****/
/****************************************/

*Col 1
xtpoisson tasa_hom interMain inter_hayCarteles inter_eneCarteles inter_supply_dpan interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles* i.timeTS, fe vce(robust)
estimates store e1

*Col 2
xtpoisson tasa_hom interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS, fe vce(robust)
estimates store e2

*Col 3
xtpoisson tasa_hom inter2 interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS, fe vce(robust)
estimates store e3


/*****   Linear model : cols 4-6     ****/
/****************************************/

*Col 4
xtreg log_tasa_hom interMain inter_hayCarteles inter_eneCarteles inter_supply_dpan interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles* i.timeTS, fe vce(robust)
estimates store e4

*Col 5
xtreg log_tasa_hom interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS, fe vce(robust)
estimates store e5

*Col 6
xtreg log_tasa_hom inter2 interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS, fe vce(robust)
estimates store e6

* Export results
estout e1 e2 e3 e4 e5 e6  using Tables/Table6pan1.tex, style(tex) ///
varlabels(interMain "Proximity to the U.S." ///
		  inter_hayCarteles "Cartel presence" ///
		  inter_dist_hayCarteles "Proximity to the U.S. $\times$ Cartel presence" ///
		  inter_eneCarteles "Various cartels" ///
		  inter_dist_eneCarteles "Proximity to the U.S. $\times$ Various cartels" ///
		  inter_supply_dpan "High PAN support" ///
		  inter_supply_dpan_dist "Proximity to the U.S. $\times$ High PAN support") ///
		  cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) labels("Observations" "R-squared"))  collabels(none) eqlabels(none) ///
		  keep(interMain inter_hayCarteles inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist) ///
		  order(interMain inter_hayCarteles inter_dist_hayCarteles  inter_eneCarteles  inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist) ///
		  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)
		  
		  
/****************************************/
/**********    Panel B     **************/
/********** Quint. 1 & 2   **************/
/****************************************/

/*****   Poisson model: cols 1-3     ****/
/****************************************/

*Col 1
xtpoisson tasa_hom interMain inter_hayCarteles inter_eneCarteles inter_supply_dpan interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles* i.timeTS if q12==1, fe vce(robust)
estimates store e1

*Col 2
xtpoisson tasa_hom interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS if q12==1, fe vce(robust)
estimates store e2

*Col 3
xtpoisson tasa_hom inter2 interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS if q12==1, fe vce(robust)
estimates store e3


/*****   Linear model : cols 4-6     ****/
/****************************************/

*Col 4
xtreg log_tasa_hom interMain inter_hayCarteles inter_eneCarteles inter_supply_dpan interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles* i.timeTS if q12==1, fe vce(robust)
estimates store e4

*Col 5
xtreg log_tasa_hom interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS if q12==1, fe vce(robust)
estimates store e5

*Col 6
xtreg log_tasa_hom inter2 interMain inter_hayCarteles  inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist interpan_* interdif_* intercart_hayCarteles* intercart_eneCarteles*  i.timeTS if q12==1, fe vce(robust)
estimates store e6

* Export results
estout e1 e2 e3 e4 e5 e6  using Tables/Table6pan2.tex, style(tex) ///
varlabels(interMain "Proximity to the U.S." ///
		  inter_hayCarteles "Cartel presence" ///
		  inter_dist_hayCarteles "Proximity to the U.S. $\times$ Cartel presence" ///
		  inter_eneCarteles "Various cartels" ///
		  inter_dist_eneCarteles "Proximity to the U.S. $\times$ Various cartels" ///
		  inter_supply_dpan "High PAN support" ///
		  inter_supply_dpan_dist "Proximity to the U.S. $\times$ High PAN support") ///
		  cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) labels("Observations" "R-squared"))  collabels(none)  eqlabels(none) ///
		  keep(interMain inter_hayCarteles inter_dist_hayCarteles inter_eneCarteles inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist) ///
		  order(interMain inter_hayCarteles inter_dist_hayCarteles  inter_eneCarteles  inter_dist_eneCarteles inter_supply_dpan inter_supply_dpan_dist) ///
		  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)



